<template>
<!-- 添加文章弹层 -->
  <el-dialog title="添加文章"  width="40%" :visible="showDialog"  @close="btnCancel" >
      <!-- 表单区域 -->
      <el-form :model="articlesForm" :rules="articlesFormRules" ref="articlesFormRef" label-width="80px" class="demo-ruleForm">
        <el-form-item label="文章标题" prop="title" class="elform">
          <el-input v-model="articlesForm.title" placeholder="请输入文章标签"></el-input>
        </el-form-item>
        <el-form-item label="文章标题" prop="articleBody" class="elform">
          <quill-editor style="hight: 0px;" v-model="articlesForm.articleBody" ref="myQuillEditor"> </quill-editor>
        </el-form-item>
        <el-form-item label="视频地址" class="elform">
          <el-input v-model="articlesForm.videoURL" placeholder="请输入视频地址"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btnCancel">取 消</el-button>
        <el-button type="primary" @click="btnOk">确 定</el-button>
      </span>
    </el-dialog>

</template>

<script>
import { quillEditor } from 'vue-quill-editor'
import Article from '../../api/hmmm/articles'

export default {
  components: {
    quillEditor
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      // 新增弹框
      addDialogVisible: false,
      // 添加验证
      articlesFormRules: {
        title: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 18, message: '长度在 3 到 18 个字符', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ]
      },
      // 添加框数据
      articlesForm: {
        title: '',
        articleBody: '',
        videoURL: null
      }

    }
  },
  methods: {
    // 点击添加请求
    async btnOk () {
      try {
        await Article.add(this.articlesForm)
        this.$message.success('新增文章成功')
        this.$emit('update:showDialog', false)
        this.$emit.getArticleList()
      } catch (error) {
        console.log(error)
      }
    },
    // 点击取消重置添加表单
    btnCancel () {
      this.$refs.articlesFormRef.resetFields()
      this.articlesForm.articleBody = ''
      this.articlesForm.videoURL = ''
      // this.$parent.showDialog = false // 关闭弹层
      this.$emit('update:showDialog', false)
    },
    // 点击预览
    previewArt (row) {
      this.articlesInfo = row
      console.log(this.articlesInfo)
      this.previewDialogVisible = true
    }

  }
}
</script>

<style scoped >
.elform {
  width: 100%;
}</style>
